#ifndef _HLFS_STORAGE_HELPER_H_
#define _HLFS_STORAGE_HELPER_H_

#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <stdint.h>
#include <fcntl.h>
#include "glib.h"
#include "storage.h"
#include "bs_local.h"
#include "bs_hdfs.h"

static struct back_storage* init_storage_handler(const char* uri,const char *fs_name)
{
    struct back_storage* storage = NULL;
    gchar **v  = g_strsplit(uri,"://",2);
    gchar * fs_path = g_build_filename(v[1],fs_name,NULL);
    g_message( "loc [fs:%s] [path:%s]\n",fs_name,fs_path);
    if (0==g_strcmp0(v[0],"local")){
        //gchar * fs_path = g_build_filename(v[1],fs_name,NULL);
        //g_message( "local [fs:%s] [path%s]\n",fs_name,fs_path);
        storage = &local_storage;
    }else if(0 == g_strcmp0(v[0],"hdfs")){
        //g_message( "hdfs storage not implement now \n");
        storage = &hdfs_storage;
    }else{
        g_message( "Error URI \n");
	g_free(fs_path);
        g_strfreev(v);
        return NULL;
    }
    if(0!=storage->bs_fs_connect(storage,uri,fs_name,"who",0)){
	g_free(fs_path);
        g_strfreev(v);
        g_message("connect filesystem failed\n");
        return NULL;
    }
    g_free(fs_path);
    g_strfreev(v);
    return storage;
}


static int deinit_storage_handler(struct back_storage * storage){
    if(storage == NULL){
       g_message("%s storage NULL\n",__func__);
       return 0;
    }
    if(0!=storage->bs_fs_disconnect(storage)){
       return -1;
    }
    g_message("%s disconnect succ\n",__func__);
    g_free(storage->storage_name);
    g_free(storage->fs_name);
    g_free(storage->fs_location);
    g_free(storage->user);
    g_message("%s over\n",__func__);
    return 0;
}

#endif
